/**
******************************************************************************************
* @file ProxyTab.h
* @brief Management of the message's emission by TCP/IP.
* @date 30 mars 2015
* @author Benjamin Lancinot
*****************************************************************************************/
/* COPYRIGHT ****************************************************************************
*****************************************************************************************
* Copyright (c) 2015, Audrey LOISEAU and Benjamin LANCINOT.
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions are met:
*
* 1. Redistributions of source code must retain the above copyright notice, this
*    list of conditions and the following disclaimer.
* 2. Redistributions in binary form must reproduce the above copyright notice,
*    this list of conditions and the following disclaimer in the documentation
*    and/or other materials provided with the distribution.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
* WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
* DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE FOR
* ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
* LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
* ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
* (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
* SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
********************************************************************************************/

#ifndef PROXYTAB_H
#define PROXYTAB_H

/*******************************************************************************************
* INCLUSION
********************************************************************************************/

#include <stdio.h>
#include <stdlib.h>
#include <pthread.h>
#include <unistd.h>
#include <stdbool.h>
#include <string.h>
#include <time.h>
#include <sys/ipc.h>
#include <sys/msg.h>
#include <sys/wait.h>
#include <sys/errno.h>


#include "Sender.h"
#include "../model/observer.h"
#include "../model/MercureLover.h"
#include "../model/Electrician.h"
#include "../model/HumidityTester.h"
#include "../model/SoundEngineer.h"
#include "../model/MercureController.h"
#include "../model/HumidityController.h"

/*******************************************************************************************
* DEFINES
********************************************************************************************/

#define MQ_MAX_MESSAGES 10
#define MQ_MSG_SIZE 1024
#define TRUE 1
#define FALSE 0

/*******************************************************************************************
* TYPES
********************************************************************************************/

/**
 * @struct ProxyTab
 */
typedef struct ProxyTab{
	int carryOn;
	pthread_t proxyTabThread;
	int BAL_id;
	Sender* sender;
	Observer* observer;

        void (*notifyBySpreader)(struct ProxyTab*, int, char*);
	void (*start)(struct ProxyTab*, int);
	void (*stop)(struct ProxyTab*);
	void (*destroy)(struct ProxyTab**);

}ProxyTab;


/**
 * @enum proxyTabActions
 */
typedef enum proxyTabActions_t{
	SEND_TEMPERATURE=0,
        SEND_LIGHT=1,
	SEND_HUMIDITY=2,
	SEND_BBSTATE=3,
	SEND_CRITICALITY_HUMIDITY=4,
	SEND_CRITICALITY_TEMPERATURE=5,
	SEND_AVERAGE_TEMPERATURE=6,
	SEND_AVERAGE_HUMIDITY=7,
        NTD=-1 //nothing to do
}proxyTabActions;


/**
 * @struct proxyTabMessage
 */
typedef struct proxyTab_message{
	proxyTabActions action;
	float valeur;
	int carryOn;
} proxyTabMessage;



/**
 * @struct BAL_msg
 */
typedef struct BAL_msg {
	long mtype;
	proxyTabMessage message;
} BAL_msg;

/*******************************************************************************************
* FUNCTIONS
********************************************************************************************/

/**
 * @brief Constructor
 * @return Pointer to a new ProxyTab
 **/
ProxyTab* ProxyTab_create();

#endif
